namespace Oracle.ManagedDataAccess.Types
{
	internal static class CoreFunctions
	{
		internal static int[] ldidom = new int[14]
		{
			0,
			0,
			31,
			59,
			90,
			120,
			151,
			181,
			212,
			243,
			273,
			304,
			334,
			365
		};

		internal static bool IsLeapYear(int y)
		{
			if (y % 4 == 0)
			{
				if (y > 1582)
				{
					if (y % 100 == 0)
					{
						return y % 400 == 0;
					}
					return true;
				}
				return y != -4712;
			}
			return false;
		}

		internal static int Cal2Days(int y, int m, int d)
		{
			return ldidom[m] + d + ((m >= 3 && IsLeapYear(y)) ? 1 : 0);
		}

		internal static int DateToJulianDays(int year, int month, int day)
		{
			int num;
			if (year == -4712)
			{
				num = 0;
			}
			else
			{
				num = year + 4712;
				num = 365 * num + (num - 1) / 4;
			}
			if (year >= 1583)
			{
				num = num - 10 - (year - 1501) / 100 + (year - 1201) / 400;
			}
			num += Cal2Days(year, month, day);
			if (year == 1582 && ((month == 10 && day >= 15) || month >= 11))
			{
				num -= 10;
			}
			return num;
		}
	}
}
